package com.example.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.WorkOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.vo.WorkOrderDetailVo;
import com.example.vo.WorkOrderVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lyj
 * @since 2023-02-20
 */
public interface WorkOrderMapper extends BaseMapper<WorkOrder> {

    @Select("select su1.name createName,\n" +
            "so.name officeName,\n" +
            "su2.name transportName,\n" +
            "su3.name recipientName,\n" +
            "wo.*\n" +
            "from work_order wo\n" +
            "left join sys_user su1 on wo.create_user_id=su1.id\n" +
            "left join sys_user su2 on wo.transport_user_id=su2.id\n" +
            "left join sys_user su3 on wo.recipient_user_id=su3.id\n" +
            "left join sys_office so on su1.office_id=so.id ${ew.customSqlSegment}")
    Page<WorkOrderVo> queryByCondition(Page<WorkOrderVo> page, QueryWrapper<WorkOrderVo> ew);

    @Select("select su1.name createUserName,\n" +
            "su1.phone createUserPhone,\n" +
            "so1.name createOfficeName,\n" +
            "su2.name transportUserName,\n" +
            "su2.phone transportUserPhone,\n" +
            "so2.name transportOfficeName,\n" +
            "su3.name recipientUserName,\n" +
            "su3.phone recipientUserPhone,\n" +
            "so3.name recipientOfficeName,\n" +
            "wo.*\n" +
            "from work_order wo\n" +
            "left join sys_user su1 on wo.create_user_id=su1.id\n" +
            "left join sys_office so1 on su1.office_id=so1.id\n" +
            "left join sys_user su2 on wo.transport_user_id=su2.id\n" +
            "left join sys_office so2 on su2.office_id=so2.id\n" +
            "left join sys_user su3 on wo.recipient_user_id=su3.id\n" +
            "left join sys_office so3 on su3.office_id=so3.id ${ew.customSqlSegment}")
    WorkOrderDetailVo queryWorkOrderByWorkOrderCode(@Param("ew") QueryWrapper<WorkOrderDetailVo> ew);
}
